﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.Controls;

namespace HYView
{
	public partial class HideBaselineForm : System.Windows.Forms.Form
	{
		public HideBaselineForm(List<string> viewPlanInfoList)
		{
			this.InitializeComponent();
			this.chkList.Items.Clear();
			for (int i = 0; i < viewPlanInfoList.Count; i++)
			{
				string item = viewPlanInfoList[i];
				this.chkList.Items.Add(item);
				this.chkList.SetItemChecked(i, false);
			}
		}

		public List<int> SelectedIndex()
		{
			List<int> list = new List<int>();
			for (int i = 0; i < this.chkList.Items.Count; i++)
			{
				if (this.chkList.GetItemChecked(i))
				{
					list.Add(i);
				}
			}
			return list;
		}

		private void btnSelAll_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.chkList.Items.Count; i++)
			{
				this.chkList.SetItemChecked(i, true);
			}
		}

		private void btnSelNone_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.chkList.Items.Count; i++)
			{
				this.chkList.SetItemChecked(i, false);
			}
		}

		private void btnSelContrary_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.chkList.Items.Count; i++)
			{
				bool value = !this.chkList.GetItemChecked(i);
				this.chkList.SetItemChecked(i, value);
			}
		}

		private void btnCloseAll_Click(object sender, EventArgs e)
		{
			for (int i = 0; i < this.chkList.Items.Count; i++)
			{
				this.chkList.SetItemChecked(i, true);
			}
		}

		private void btnCloseSel_Click(object sender, EventArgs e)
		{
		}

		private void HideBaselineForm_FormClosing(object sender, FormClosingEventArgs e)
		{
			if (((System.Windows.Forms.Form)sender).DialogResult == DialogResult.OK)
			{
				if (this.chkList.Items.Count == 0)
				{
					return;
				}
				if (this.SelectedIndex().Count == 0 && YJKMessageBox.Show("未选中任何视图，是否退出？", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.Cancel)
				{
					e.Cancel = true;
					return;
				}
			}
		}

		private void chkList_MouseClick(object sender, MouseEventArgs e)
		{
			if (this.chkList.SelectedItem != null && ((ListBox)sender).IndexFromPoint(e.X, e.Y) == -1)
			{
				this.chkList.ClearSelected();
			}
		}

		private void chkList_MouseDoubleClick(object sender, MouseEventArgs e)
		{
			if (this.chkList.SelectedItem != null && ((ListBox)sender).IndexFromPoint(e.X, e.Y) == -1)
			{
				this.chkList.ClearSelected();
			}
		}
	}
}
